import json
import random

import redis
from ronglian_sms_sdk import SmsSDK

from utils.My_celery import app

# 自己在容联云注册得到的ID


accId = ' '
accToken = ' '
appId = ' '


@app.task
def send_message(phone):
    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    data = random.randint(100000, 999999)
    red = redis.Redis(host='127.0.0.1', port=6379)
    red.setex(str(phone), 300, data)
    red.set('time_%s' % phone, data, ex=50)
    datas = (data, '5')
    resp = sdk.sendMessage(tid, phone, datas)
    resp_json = json.loads(resp)
    return resp_json
